package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Folder;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class FODao {

	DBHelp<Folder> db=new DBHelp<Folder>();
	
	public void save(Folder folder){
		String sql="insert into t_folder(id,foname,createtime,employeeid,projectid) values(?,?,?,?,?)";
		db.executeSQL(sql,folder.getId(),folder.getFoname(),folder.getCreatetime(),folder.getEmployeeid(),folder.getProjectid());
	}
	
	public void delete(String id){
		String sql="delete from t_folder where id=?";
		db.executeSQL(sql,id);
	}
	
	public List<Folder> findByProjectid(String projectid){
		String sql="select * from t_folder where projectid=? order by createtime";
		return db.queryForList(sql,new FORowMapper(),projectid);
	}
	
	
	
	private class FORowMapper implements RowMapper<Folder>{

		public Folder mapperRow(ResultSet rs) throws SQLException {
			
			Folder folder=new Folder();
			folder.setCreatetime(rs.getString("createtime"));
			folder.setEmployeeid(rs.getInt("employeeid"));
			folder.setFoname(rs.getString("foname"));
			folder.setId(rs.getString("id"));
			folder.setProjectid(rs.getString("projectid"));
			return folder;
			
		}
		
	}
}

